﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArrayOperations
{
    public partial class Form1 : Form
    {
        int rndmNumber;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox.Items.Clear();
            
            int[] numArray = new int[20];
            Random rndm = new Random();
            for (int j = 0; j <= 19; j++)
            {
                rndmNumber = rndm.Next(20) + 1;
                numArray[j] = rndmNumber;

            }

            foreach (var item in numArray)
            {
                listBox.Items.Add(item.ToString());
            }

            //smallest in the array
            int smallest = numArray[0];
            for (int i = 0; i < numArray.Length; i++)
            {
                if (numArray[i] < smallest)
                {
                    smallest = numArray[i];
                }
            }
            textBoxLow.Text = smallest.ToString();
            
            //biggest in the array
            int biggest = numArray[0];
            for (int i = 0; i < numArray.Length; i++)
            {
                if (numArray[i] > biggest)
                {
                    biggest = numArray[i];
                }
            }
            textBoxHigh.Text = biggest.ToString();

            //count nunmber of elements

            int coutner = 0;
            for (int i = 0; i < numArray.Length; i++)
            {
                coutner++;
            }

            textBoxCountElm.Text = coutner.ToString();

            //sum all elements in the array
            int sum = 0;
            for (int i = 0; i < numArray.Length; i++)
            {
                sum += numArray[i];
            }
            textBoxAVG.Text = (sum/coutner).ToString();

            //number of odd elements
            int oddElements = 0;
            foreach (var item in numArray)
            {
                if (item % 2 != 0)
                {
                    oddElements++;
                }
            }
            textBoxOddElm.Text = oddElements.ToString();
        }
    }
}
